# vim: syntax=perl:ts=4:sw=4
sub mm_form_groupaccess_to_portal_populate2($$) {
my $portal=$_[0];
my $group_pattern=$_[1];

	# my $s="<input type=hidden name=portal value=\"$portal\"/>";
	my $p2=hex_to_string($portal);
	if($group_pattern =~ /not defined/) {
		$group_pattern="";
	} else {
		$group_pattern=hex_to_string($group_pattern);
	}
	#########################################################################
	# Firstly we define a table with the currently defined groups - if 	    #
	# any that are defined for this poprtal.
	#########################################################################
	my $button="<input type=submit name=\"search\" value=\"Search\"";
	my $s="<tr><td class=gri_cell><input width=80 type=text name=group_pattern value=\"$group_pattern\"/></td><td>$button</td>" ;

	#########################################################################
	# If group_pattern is not "" then show possible matches the user can	#
	# add - though limit it if larger than 1000!!							#
	#########################################################################
	if(length($group_pattern)) {
		my ($rc,$matches)=$::GRI_FRONTEND->group_matches($group_pattern);
		if($rc==1 && defined($matches)) {
			my $row=0;
			for my $cg (@$matches) {
				my $class="gri_odd";
				$class="gri_even" if $row%2==0;
				my $gh=string_to_hex($cg);
				$s.="<tr class=gri_row id=$class><td class=gri_cell>$cg</td>";
				if(exists($::PARAM{"RR_$gh"}) && $::PARAM{"RR_$gh"} == 1) {
					$s.="<td class=gri_cell-right width=10%><input type=checkbox name=\"RR_$gh\" value=1 checked=yes></td></tr>";
				} else {
					$s.="<td class=gri_cell-right width=10%><input type=checkbox name=\"RR_$gh\" value=1></td></tr>";
				}
				$row++;
			}
		}
	}
	return $s;
}
